<template>
	<view class="content padding">
		<view class="coupon_view" v-for="(item,index) in coupon.able" :key="index" @tap="useCoupon(item.id)">
			<view class="coupon_amount">
				¥
				<view style="font-size: 70upx;font-weight: 800;">
					{{item.amount}}
				</view>
			</view>
			<view style="flex-direction: column;flex: 1;">
				<view style="font-size: 30upx;font-weight: 700;color: #333333">{{item.title}}</view>
				<view style="font-size: 24upx;color: #555555;margin-top: 15upx;">· {{item.amountCondition}}</view>
				<view style="font-size: 24upx;color: #555555;">· {{item.productCondition}}</view>
				<view style="font-size: 24upx;color: #555555;">· {{item.expireTime}}</view>
			</view>

			<view style="width: 60upx;justify-content: center;">
				<view class="coupon_choice"></view>
			</view>

		</view>
		<view class="coupon_view_unable" v-for="(item,index) in coupon.unable" :key="index">
			<view style="width: 100%;align-items: center;">
				<view class="coupon_amount" style="color: #888888;">
					¥
					<view style="font-size: 70upx;font-weight: 800;">
						{{item.amount}}
					</view>
				</view>
				<view style="flex-direction: column;flex: 1;">
					<view class="coupon_title">{{item.title}}</view>
					<view class="coupon_condition" style="margin-top: 15upx;">· {{item.amountCondition}}</view>
					<view class="coupon_condition">· {{item.productCondition}}</view>
					<view class="coupon_condition">· {{item.expireTime}}</view>
				</view>
			</view>
			<view class="coupon_unable_condition">
				<view style="color: #FE0036;">· </view>
				{{item.errMsg}}
			</view>

		</view>
	</view>
</template>

<script>
	import api from '../../common/api.js';
	import {
		getWithParam_
	} from '../../common/request.js';
	import {
		parseParam
	} from '../../common/util.js';
	export default {
		data() {
			return {
				coupon: [],
				param: {}
			}
		},
		onLoad(option) {
			if (option.skuId != null) {
				var p = {
					skuId: option.skuId,
					count: option.count
				}
				this.initData(p)
			} else {
				var p = {
					cartId: option.cartId
				}
				this.initData(p)
			}
			this.param = option
		},
		methods: {
			useCoupon(id) {
				this.param.couponId = id
				uni.navigateTo({
					url: "../order/index?" + parseParam(this.param)
				})
			},
			initData(p) {
				getWithParam_(api.COUPON_CHOICE, p).then(res => {
					this.coupon = res.data
				})
			}
		}
	}
</script>

<style>
	.coupon_title {
		font-size: 30upx;
		font-weight: 700;
		color: #888888
	}

	.coupon_choice {
		width: 30upx;
		height: 30upx;
		border-radius: 30upx;
		border: 3upx solid #888888;
	}

	.coupon_condition {
		font-size: 24upx;
		color: #888888;
	}

	.coupon_view {
		position: relative;
		overflow: hidden;
		background-color: #FFFFFF;
		border-radius: 10upx;
		padding: 30upx 20upx;
		align-items: center;
		margin: 20upx 0;
	}

	.coupon_amount {
		color: #FE0036;
		align-items: flex-end;
		width: 250upx;
		justify-content: center;
	}

	.coupon_view_unable {
		background-color: #FFFFFF;
		border-radius: 10upx;
		padding: 30upx 20upx 10upx 20upx;
		margin: 20upx 0;
		flex-direction: column;
	}

	.coupon_unable_condition {
		border-top: 3upx dashed #888888;
		width: 100%;
		margin-top: 20upx;
		color: #555555;
		font-size: 20upx;
		align-items: center;
		padding-top: 10upx;
	}
</style>
